import Vue from 'vue'
import VueRouter from 'vue-router'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home.vue'),
    children: [
      {
        path: "",
        name: "Index",
        component: () => import('../views/Index.vue')
      }, {
        path: "/index",
        redirect: "/"
      }, {
        path: "/blog/:id",
        name: "BlogDetail",
        component: () => import('../views/BlogDetail')
      }, {
        path: "/tag/blogList",
        name: "TagBlogList",
        component: () => import('../views/TagBlogList')
      }, {
        path: "/category/blogList",
        name: "CategoryBlogList",
        component: () => import('../views/CategoryBlogList')
      }
    ],
  },
  {
    path: '/admin',
    name: 'Admin',
    redirect: "/admin/blog",
    component: () => import('../views/admin/Admin'),
    children: [
      {
        path: '/admin/blog',
        name: 'BlogList',
        component: () => import('../views/admin/BlogList')
      },
      {
        path: '/admin/blog/save/:id',
        name: 'BlogSave',
        component: () => import('../views/admin/BlogSave')
      },
      {
        path: '/admin/category',
        name: 'CategoryList',
        component: () => import('../views/admin/CategoryList')
      },
      {
        path: '/admin/category/save',
        name: 'CategorySave',
        component: () => import('../views/admin/CategorySave')
      },
      {
        path: '/admin/tag',
        name: 'TagList',
        component: () => import('../views/admin/TagList')
      },
      {
        path: '/admin/tag/save',
        name: 'TagSave',
        component: () => import('../views/admin/TagSave')
      },
      {
        path: '/admin/menu',
        name: 'MenuList',
        component: () => import('../views/admin/MenuList')
      },
      {
        path: '/admin/menu/save',
        name: 'MenuSave',
        component: () => import('../views/admin/MenuSave')
      },
      {
        path: '/admin/user',
        name: 'UserList',
        component: () => import('../views/admin/UserList')
      },
      {
        path: '/admin/user/save',
        name: 'UserSave',
        component: () => import('../views/admin/UserSave')
      },
      {
        path: '/admin/myself',
        name: 'MySelf',
        component: () => import('../views/admin/MySelf')
      },
    ]
  },
  {
    path: '/auth',
    name: 'Auth',
    redirect: '/login',
    component: () => import('../views/auth/Auth'),
    children: [
      {
        path: '/login',
        name: 'Login',
        component: () => import('../views/auth/Login')
      },
      {
        path: '/register',
        name: 'Register',
        component: () => import('../views/auth/Register')
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
